package main.java.indi.zyj.c150.dps;

import java.util.Scanner;

public class _13_Sudoku {

    static String[][] chessboard = new String[10][10];
    static boolean[][] vx = new boolean[10][10];
    static boolean[][] vy = new boolean[10][10];
    static boolean[][] vv = new boolean[10][10];
    static boolean f;

    static void Dfs(int x, int y){
        if (f){
            return;
        }
        if (x == 9){
            f = true;
            for (int i = 0; i < 9; i++) {
                for (int j = 0; j < 9; j++) {
                    if (j == 8){
                        System.out.println(chessboard[i][j]);
                    }else {
                        System.out.print(chessboard[i][j]);
                    }
                }
            }
            return;
        }
        if (y == 9){
            Dfs(x + 1, 0);
            return;
        }
        if (!chessboard[x][y].equals("*")){
            Dfs(x, y+1);
            return;
        }
        for (int i = 1; i <= 9; i++) {
            if (!vx[x][i] && !vy[y][i] && !vv[x / 3 * 3 + y / 3][i] ){
                chessboard[x][y] = i + "";
                vx[x][i] = true;
                vx[y][i] = true;
                vx[x / 3 * 3 + y / 3][i] = true;
                Dfs(x, y+1);
                vx[x][i] = false;
                vx[y][i] = false;
                vx[x / 3 * 3 + y / 3][i] = false;
                chessboard[x][y] = "*";
            }
        }
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        for (int i = 0; i < 9; i++) {
            String s = scan.next();
            for (int j = 0; j < 9; j++) {
                chessboard[i][j] = s.charAt(j) + "";
            }
        }
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                if (!chessboard[i][j].equals("*")){
                    vx[i][Integer.parseInt(chessboard[i][j])] = true;
                    vx[j][Integer.parseInt(chessboard[i][j])] = true;
                    vx[i / 3 * 3 + j / 3][Integer.parseInt(chessboard[i][j])] = true;
                }
            }
        }
        Dfs(0, 0);

    }

}
